-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[2/n] add newtype wrappers to ensure config identifier validity #69
[2/n] add newtype wrappers to ensure config identifier validity #69
Conversation
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1 [skip ci]
src/config/identifier.rs
Outdated
use serde::{Deserialize, Serialize}; | ||
use thiserror::Error; | ||
|
||
/// A unique identifier for a configuration parameter. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Makes sense to codify this a little better, thanks!
} | ||
} | ||
|
||
impl<'de> Deserialize<'de> for ConfigIdent { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why manually implement Deserialize but not Serialize?
Is it worth adding a test that we can serialize -> deserialize -> re-serialize?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Deserialize
must go through validation, while serialization doesn't have to. Definitely worth writing a test for.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added tests and a comment explaining this.
@@ -12,10 +12,12 @@ use std::path::Path; | |||
use thiserror::Error; | |||
use topological_sort::TopologicalSort; | |||
|
|||
use super::ConfigIdent; | |||
|
|||
/// Describes a set of packages to act upon. | |||
/// | |||
/// This structure maps "package name" to "package" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you think it's worth it to make a thin wrapper around ConfigIdent
to label this as a PackageName
specifically?
I'm assuming that with other configuration parameter usage, there will be other uses of ConfigIdent
that are semantically different.
(If you want to punt this beyond this PR, I'm also fine with that)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per discussion in DMs, ended up creating three newtypes -- one each for package names, service names and preset names.
Created using spr 1.3.6-beta.1 [skip ci]
Created using spr 1.3.6-beta.1
Created using spr 1.3.6-beta.1
I'm going to add some more identifiers soon, and I wanted to make sure at
deserialize time that they were somewhat well-formed. We restrict ourselves to
ASCII at the moment, which is fine.
Add three newtype wrappers -- one each for package, service and preset names.
Depends on: